var url = require('url');
var template = require('templateConfig');
var main = require('main');
var form = require('form');
var module= require('module');
//模板配置
var tplArr = [];
var modalTpl =require('raw!../template/modal.txt'); 
var personalTpl =require('raw!../template/personal-center.txt'); 
tplArr['modal'] = template.compile(modalTpl.replace(/^\s*|\s*$/g, "")); 
tplArr['personal'] = template.compile(personalTpl.replace(/^\s*|\s*$/g, "")); 

function Index(){
    _this = this;
    this.main = function(){
        main.event(this,'tap','i-click'); 
        this.init();
    }     

    /**
     * @param  {string} page "come from which page"
     */
    this.getContent= function(page){
        var baseUrl= _this.baseUrl;
        var data= {
            tType: "content"
        };

        //个人信息
        var data_headgrid= {
            tType: "headgrid",
            image: "",
            title: "Golan Yao",
            tag: "超级粉丝",
            // content: "God"
        };
        //积分
        var data_account= {
            tType: "account",
            key: "当前积分",
            val: "1200",
            name: "去积分商城"
        };
        //超链接列表
        var data_arrlist= {
            tType: "arrlist",
            dataList: [{
                name: "我的优惠券",
                link: ""
            },{
                name: "我收藏的商品",
                link: ""
            },{
                name: "我的收货地址",
                link: ""
            }]
        };
        //申请加入说明
        var data_partner= {
            tType: "partner",
            title: "恭喜您！您已成为【超级粉丝】有机会成为【虚拟店员】",
            description: "虚拟店员可获得虚拟店员专享二维码，享有8折拿货。",
            link: "javascript:;",
            fun:'i-click="showRules"',
            name: "大家乐会员规则"
        };         
        //我的订单
        var data_tabblock= {
            tType: "tabblock",
            title: "我的订单",
            baseUrl: baseUrl,
            dataList: [{
                image: "order_1.jpg",
                name: "全部订单",
                click: 'jump1',
                cornernum: ""
            },{
                image: "order_2.jpg",
                name: "待付款",
                click: 'jump2',
                cornernum: ""
            },{
                image: "order_3.jpg",
                name: "代收货",
                click: 'jump3',
                cornernum: ""
            },{
                image: "order_4.jpg",
                name: "待评价",
                click: 'jump4',
                cornernum: ""
            },{
                image: "order_5.jpg",
                name: "退换货",
                click: 'jump5',
                cornernum: ""
            }]
        }; 
       
        main.post(url.clerOpenidkSingle,{},function(res){
            var ret=res.data;
            data_headgrid.title=ret.clerk_name;
            if(ret.integral==null){
                data_account.val=0;
            }
            if(ret.status==1){
                data_headgrid.tag="加盟商";
            }
            else if(ret.status==2){data_headgrid.tag="店长";}
            else if(ret.status==3){data_headgrid.tag="店员";}
            else if(ret.status==4){data_headgrid.tag="门店合伙人";}
            else if(ret.status==5){data_headgrid.tag="普通合伙人";}
            else if(ret.status==6){data_headgrid.tag="粉丝";}

            switch(page){
                case "process":
                //普通合伙人
                data_headgrid.tag="普通合伙人";
                data_partner.title="您已成为【普通合伙人】有机会成为【门店合伙人】";
                data_partner.description= "虚拟店员可获得虚拟店员专享二维码，享有8折拿货。";
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock");
                data.account= module.getModule(data_account, "account");
                data.arrlist= module.getModule(data_arrlist, "arrlist");
                data.partner= module.getModule(data_partner, "partner");
                data.btnName= "申请成为虚拟店员";
                data.btnClick= "";
                break;

                case "storepartner":
                //门店合伙人            
                data_headgrid.tag="门店合伙人";
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock");
                data.account= module.getModule(data_account, "account");
                data.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;

                case "clerkmember":
                //店员      
                data_headgrid.tag="店员";
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock");
                data.account= module.getModule(data_account, "account");
                data.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;

                case "clerkmaster":  
                //店长      
                data_headgrid.tag="店长";
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock");
                data.account= module.getModule(data_account, "account");
                data.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;          

                case "visual":
                data_headgrid.tag="虚拟店员";
                // data_headgrid.qrcode="http://placeholder.qiniudn.com/100x100";
                // data_headgrid.qrlink="";
                data_arrlist= {
                tType: "arrlist",
                dataList: [{
                        name: "订单管理",
                        link: ""
                    },{
                        name: "我的优惠券",
                        link: ""
                    },{
                        name: "粉丝订单",
                        link: ""
                    },{
                        name: "我的佣金",
                        link: ""
                    },{
                        name: "我收藏的商品",
                        link: ""
                    },{
                        name: "我的收货地址",
                        link: ""
                    }]
                };
                data_partner= {
                    tType: "partner",
                    title: "恭喜您！您满足条件，有机会申请成为【品牌大使】",
                    description: "品牌大使可获得品牌大使专享二维码，享有65折拿货。",
                    link: "",
                    name: "大家乐会员规则"
                };  
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock"); 
                data.arrlist= module.getModule(data_arrlist, "arrlist");
                data.partner= module.getModule(data_partner, "partner");
                data.btnName= "申请成为品牌大使";
                data.btnClick= "";
                break;

                case "clerkmember":
               
                data_headgrid.tag="虚拟店员";
                // data_headgrid.qrcode="http://placeholder.qiniudn.com/100x100";
                // data_headgrid.qrlink="";
                data_arrlist= {
                tType: "arrlist",
                dataList: [{
                        name: "我的优惠券",
                        link: ""
                    },{
                        name: "粉丝订单",
                        link: ""
                    },{
                        name: "我的佣金",
                        link: ""
                    },{
                        name: "我收藏的商品",
                        link: ""
                    },{
                        name: "我的收货地址",
                        link: ""
                    }]
                };
                data_partner= {
                    tType: "partner",
                    title: "恭喜您！您满足条件，有机会申请成为【品牌大使】",
                    description: "品牌大使可获得品牌大使专享二维码，享有65折拿货。",
                    link: "",
                    name: "大家乐会员规则"
                };  
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock"); 
                data.arrlist= module.getModule(data_arrlist, "arrlist");
                data.partner= module.getModule(data_partner, "partner");
                data.btnName= "申请成为品牌大使";
                data.btnClick= "";
                break;

                case "clerkmaster":            
                data_headgrid.tag="店长";
                // data_headgrid.qrcode="http://placeholder.qiniudn.com/100x100";
                // data_headgrid.qrlink="";
                data_arrlist= {
                tType: "arrlist",
                dataList: [{
                        name: "订单管理",
                        link: ""
                    },{
                        name: "我的优惠券",
                        link: ""
                    },{
                        name: "粉丝订单",
                        link: ""
                    },{
                        name: "我的佣金",
                        link: ""
                    },{
                        name: "我收藏的商品",
                        link: ""
                    },{
                        name: "我的收货地址",
                        link: ""
                    }]
                }; 
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock"); 
                data.arrlist= module.getModule(data_arrlist, "arrlist"); 
                data.account= module.getModule(data_account, "account");
                break;

                case "alliance":          
                data_headgrid.tag="";
                data.headgrid= module.getModule(data_headgrid, "headgrid");
                data.tabblock= module.getModule(data_tabblock, "tabblock"); 
                data.arrlist= module.getModule(data_arrlist, "arrlist"); 
                data.account= module.getModule(data_account, "account");
                break;
            } 
            $(".content").html(tplArr['personal'](data));
        }); 
    }
    this.showRules=function(){
        main.botActionsheet({
            "content":"大家乐规则",
        })
    }
    this.jump1=function(){
        window.location.href=url.orderManager;
    }
    this.jump2=function(){
        window.location.href=url.orderManager+'?order_status=pay_0';
    }
    this.jump3=function(){
        window.location.href=url.orderManager+'?order_status=shipping_1';
    }
    this.jump4=function(){
        window.location.href=url.orderManager+'?order_status=assess_1';
    }
    this.jump5=function(){
        window.location.href=url.orderManager+'?order_status=return_4';
    }
    //inital page
    this.init= function(){ 
        this.page= _page;
        // this.openid=_openid;
        this.baseUrl= url.baseImageUrl;
 
        this.getContent(this.page);
    }
    return this.main();
};

var index = new Index();